import { queryPerson } from '@/utils/common';
import AdSelect from '@/components/AdSelect';
import AdSearch from '@/components/AdSearch';

export const codes = {
  page: 'STANDAROILWEEARPAGE',
  select: 'STANDAROILWEEARPAGE_SELECT',
  showDetail: 'STANDAROILWEEARPAGE_VIEW',
  add: 'STANDAROILWEEARPAGE_ADD',
  edit: 'STANDAROILWEEARPAGE_UPD',
  remove: 'STANDAROILWEEARPAGE_DEL',
};
export const EmptyList = [{ code: 'true', value: '是' }, { code: 'false', value: '否' }];

export const allUrl = {
  userList: 'tms/tms-bill/selectUserList_s',
};

export const routeUrl = {
  add: '/carBasic/cabinetOilList/addCabinetOil',
  edit: '/carBasic/cabinetOilList/editCabinetOil',
};

export const allDispatchType = {
  list: 'cabinetOil/selectCabinetOilList',
  detail: 'cabinetOil/selectCabinetOilDetail',
  remove: 'cabinetOil/removeCabinetOil',
  operate: 'cabinetOil/cabinetOilOperate',
  value: 'cabinetOil/allValus',
};

export function renderTableAdSelect({ key, data, value, props }) {
  let params = { onlyRead: true, value };
  if (key) {
    const { dictObject } = props;
    params = { data: dictObject[key], payload: { code: [key] }, ...params };
  } else {
    params = { data, ...params };
  }
  return <AdSelect {...params} />;
}

export function renderTableAdSearch({ value, props }) {
  if (!value || !searchValue) return '';
  const { searchValue } = props;
  const params = {
    onlyRead: true,
    value: searchValue[value],
    label: 'loginName',
    name: 'sysName',
  };
  return <AdSearch {...params} />;
}

export function selectCabinetOilList({ payload = {}, props } = {}) {
  const { dispatch, searchValue } = props;
  dispatch({
    type: allDispatchType.list,
    payload,
    callback: data => {
      if (!data) return;
      queryPerson({ data, props: props, url: allUrl.userList });
    },
  });
}

export function selectCabinetOilDetailAndInfo({ type, payload, props, callback }) {
  const { dispatch } = props;
  dispatch({
    type,
    payload,
    callback: data => {
      if (!data) return;
      callback && callback(data);
    },
  });
}

export function saveAllValues({ payload = {}, props } = {}) {
  const { dispatch } = props;
  dispatch({
    type: 'cabinetOil/allValus',
    payload,
  });
}
